//
//  LXOrderDetailVC.m
//  lixing
//
//  Created by ypj on 2022/6/25.
//

#import "LXAppointmemtDetailVC.h"
#import "LXBookingTimeView.h"
#import "LXBookingCarInfoView.h"
#import "LXAppointmentModel.h"
#import "LXCarLeaseApplyViewController.h"
@interface LXAppointmemtDetailVC ()

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) LXBookingTimeView *bookingTimeView;      //预约时间view
@property (nonatomic, strong) LXBookingCarInfoView *carInfoView;
@property (nonatomic, strong) LXAppointmentModel *model,*carTypeModel;
@end

@implementation LXAppointmemtDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *topImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, KHeightScale(290))];
    topImg.image = [UIImage imageNamed:@"orderDetailTop_Img"];
    [self.view addSubview:topImg];
    [self layoutCustomNavWithWhiteColor:self.view title:@"预约详情"];
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, topImg.Y_height, ScreenWidth, ScreenHeight)];
    backView.backgroundColor = [UIColor colorWithHexString:@"#FAFBFC"];
    [self.view addSubview:backView];
    [self loadData];
  
}
- (void)loadData{
    
    NSDictionary *dic = @{@"id":self.Id};
    [MSNetworkManager getRevertUrl:[DOMAIN_URL stringByAppendingString:GET_GetTappointmentById] params:dic success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if(isSuccess){
            
            self.model = [LXAppointmentModel mj_objectWithKeyValues:resonseObj[@"appointment"]];
            
            
            LXAppointmentModel *mm = [LXAppointmentModel mj_objectWithKeyValues:resonseObj[@"carType"]];
            self.model.carTypeId = mm.ID;
            self.model.endurance = mm.endurance;
            self.model.energeType = mm.energeType;
            self.model.runPlatfom = mm.runPlatfom;
            self.model.carType = mm.carType;
            
            
            [self layoutUI];
        }
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
      
    } withShowHud:YES];
    
    
  
}
- (void)layoutUI
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kViewTopHeight, ScreenWidth, ScreenHeight - kViewTopHeight)];
    [self.view addSubview:self.scrollView];
    [self layoutbookingTimeView];
}

#pragma mark =====预约时间view====
- (void)layoutbookingTimeView
{
    CGFloat height = 110;
    self.bookingTimeView = [[LXBookingTimeView alloc] initWithFrame:CGRectMake(10, 20, ScreenWidth - 20,  height)];
    self.bookingTimeView.model = self.model;
    [self.scrollView addSubview:self.bookingTimeView];
  
    self.carInfoView = [[LXBookingCarInfoView alloc] initWithFrame:CGRectMake(10, _bookingTimeView.Y_height + 10, ScreenWidth - 20, 160 + 231)];
    self.carInfoView.model = self.model;
    [self.carInfoView.tipsBtn2 whenTapped:^{
       
        LXCarLeaseApplyViewController *vc = [[LXCarLeaseApplyViewController alloc] init];
        CheLiangModel *model = [[CheLiangModel alloc] init];
        model.carBrand = self.model.carBrand;
        model.carMode = self.model.carMode;
        model.ID = self.model.carBrandId;
        model.endurance = self.model.endurance;
        model.energeType = [self.model.energeType intValue];
        model.runPlatfom = self.model.runPlatfom;
        model.carType = self.model.carType;
        // 预约id
        model.appointmentId = self.model.ID;
        if (StringIsEmpty(self.model.carTypeId)) {
            vc.type = 1;
        }
        vc.detailLease = YES;
        vc.carModel = model;
        vc.fromVc = self.fromVc;
        [self.navigationController pushViewController:vc animated:YES];

        
    }];

    [self.scrollView addSubview:self.carInfoView];
    
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

    if (!StringIsEmpty(app.appointCarImageUrl)) {
        
        UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(20, self.carInfoView.Y_height + 10, ScreenWidth - 40, 0)];
        imgV.contentMode = UIViewContentModeScaleAspectFill;
        [self.scrollView addSubview:imgV];
        
        [imgV sd_setImageWithURL:[NSURL URLWithString:app.appointCarImageUrl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            imgV.height = image.size.height;
            imgV.image = image;
            
            self.scrollView.contentSize = CGSizeMake(ScreenWidth,imgV.Y_height + 40);
        }];
    }
    else {
        self.scrollView.contentSize = CGSizeMake(ScreenWidth,self.carInfoView.Y_height + 20);
    }
    
}

@end
